﻿Public Class clsStandingBook

    Public Function insert(en As entityStandingBook) As Integer
        Dim sql As String = String.Empty
        Dim rtn As Integer
        sql &= "INSERT INTO sf.b_pq_standing_book( factory_id , technology_id , oper_date, prod_date , paint_brand , "
        sql &= "primer_count , primer_curing_agent_count , topcoat_count , topcoat_curing_agent_count , medium_paint_count , medium_paint_curing_agent_count , "
        sql &= "spot_inspector , confirmer, update_time) "
        sql &= "VALUES ( ?, ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , ? , (SELECT CURRENT_TIMESTAMP(6)))"
        With en
            rtn = DBacs.ExecuteUpdateSql(sql, -1, .factory_id, .technology_id, .oper_date, .prod_date, .paint_brand,
                                         .primer_count, .primer_curing_agent_count, .topcoat_count, .topcoat_curing_agent_count, .medium_paint_count, .medium_paint_curing_agent_count,
                                         .spot_inspector, .confirmer)
        End With
        Return rtn
    End Function

    Public Function update(en As entityStandingBook) As Integer
        Dim sql As String = String.Empty
        Dim rtn As Integer
        sql &= " UPDATE sf.b_pq_standing_book SET oper_date = ? , prod_date = ? , paint_brand = ? , primer_count = ? "
        sql &= " , primer_curing_agent_count = ? , topcoat_count = ?, topcoat_curing_agent_count = ?, medium_paint_count = ?, medium_paint_curing_agent_count = ?, spot_inspector = ? "
        sql &= " , confirmer = ?, update_time = (SELECT CURRENT_TIMESTAMP(6))"
        sql &= " WHERE sys_id = ? "
        With en
            rtn = DBacs.ExecuteUpdateSql(sql, -1, .oper_date, .prod_date, .paint_brand, .primer_count,
                                         .primer_curing_agent_count, .topcoat_count, .topcoat_curing_agent_count, .medium_paint_count,
                                         .medium_paint_curing_agent_count, .spot_inspector, .confirmer, .sys_id)
        End With
        Return rtn
    End Function

    Public Function selectBySysid(_sysid As String) As DataTable
        Dim szSql As String = "select a.*,b.requirement,b.control_point from sf.b_pq_standing_book a left join sf.t_mst_technology b on a.technology_id::integer = b.sys_id where a.factory_id=? and a.sys_id=?"
        Return DBacs.ExecuteSql(szSql, -1, "TS", _sysid)
    End Function

    Public Function getList(startTime As String, endTime As String) As DataTable
        Dim szSql As String = ""
        szSql &= " select * from sf.b_pq_standing_book "
        szSql &= " where 1=1 "
        If startTime <> "" Then
            szSql &= " and update_time >= '" + startTime + "'"
        End If
        If endTime <> "" Then
            szSql &= " and update_time <= '" + endTime + "'"
        End If
        Return DBacs.ExecuteSql(szSql, -1)
    End Function

End Class
